package com.lsl.legcommune.ui;

import com.lsl.legcommune.ui.helper.FragmentTabManager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class MainActivity extends FragmentActivity {
    
	private TabHost tabHost;
	private FragmentTabManager fragmentTabManager;
	
	private RadioGroup radioGroup;
	
	private static final String TABTAG_MYCOMMUNE = "TABTAG_MYCOMMUNE";
	private static final String TABTAG_NETCOMMUNE = "TABTAG_NETCOMMUNE";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tabHost = (TabHost)this.findViewById(android.R.id.tabhost);
        tabHost.setup();
        
        fragmentTabManager = new FragmentTabManager(this,tabHost,R.id.main_top_right_realtabcontent);
        
        fragmentTabManager.addTab(tabHost.newTabSpec(TABTAG_MYCOMMUNE).setIndicator(TABTAG_MYCOMMUNE),MyCommuneFragment.class,null);
        fragmentTabManager.addTab(tabHost.newTabSpec(TABTAG_NETCOMMUNE).setIndicator(TABTAG_NETCOMMUNE),NetCommuneFragment.class,null);
        
        if (savedInstanceState != null) {
        	tabHost.setCurrentTabByTag(savedInstanceState.getString("tabTag"));
        }
        
        radioGroup=(RadioGroup)findViewById(R.id.main_top_left_radiogroup);
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {				
				switch(checkedId){
					case R.id.main_top_left_radio_1:
						tabHost.setCurrentTabByTag(TABTAG_MYCOMMUNE);
						break;
					case R.id.main_top_left_radio_2:
						tabHost.setCurrentTabByTag(TABTAG_NETCOMMUNE);
						break;
					default :
						tabHost.setCurrentTabByTag(TABTAG_MYCOMMUNE);
						break;						
				}
			}
		});
                
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("tabTag", tabHost.getCurrentTabTag());
    }
    
    
}